package chat.client

import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.net.Socket

class ChatClient {
    val socket = Socket("127.0.0.1", 12345)

    fun beginChat() {
        Thread(object : Runnable {
            override fun run() {
                val br = BufferedReader(InputStreamReader(System.`in`))
                val pw = PrintWriter(socket.getOutputStream())
                while (true) {
                    val str = br.readLine()
                    pw.println(str)
                    pw.flush()
                }
            }
        }).start()
        Thread(object : Runnable {
            override fun run() {
                val br = BufferedReader(InputStreamReader(socket.getInputStream()))
                while (true) {
                    val str = br.readLine()
                    println(str)
                }
            }
        }).start()
    }
}